using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Text;

namespace SqlToolkit.Oracle.Schema
{
    public class SqlDbTableField : SqlDbTableFieldBase
    {
        internal SqlDbTableField(OracleDB conn) { _conn = conn; }

        #region TABLE_NAME
        protected string table_name = string.Empty;
        public string TableName
        {
            get { return table_name; }
            //set{if(value != table_name) table_name = value;}
        }
        #endregion
        internal static SqlDbTableField Build(OracleDB conn, System.Data.IDataReader r)
        {
            SqlDbTableField ret = new SqlDbTableField(conn);

            ret.table_name = (r.IsDBNull(0)) ? string.Empty : r.GetString(0);
            ret.column_name = (r.IsDBNull(1)) ? string.Empty : r.GetString(1);
            ret.data_type = (r.IsDBNull(2)) ? string.Empty : r.GetString(2);
            ret.column_default = (r.IsDBNull(3)) ? string.Empty : r.GetString(3);
            ret.charachter_maximum_length = (r.IsDBNull(4)) ? 0 : Convert.ToDouble(r.GetValue(4));
            ret.ordinal_position = (r.IsDBNull(5)) ? 0 : Convert.ToDecimal(r.GetValue(5));
            ret.data_length = (r.IsDBNull(6)) ? 0 : Convert.ToInt32(r[6]);
            ret.data_precision = (r.IsDBNull(7)) ? 0 : Convert.ToInt32(r[7]);

            try
            {
                ret._user = (r.IsDBNull(8)) ? string.Empty : Convert.ToString(r[8]);
            }
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); }

            return ret;
        }

        internal static SqlDbTableFieldCollection BuildCollection(OracleDB conn, System.Data.IDataReader r)
        {
            SqlDbTableFieldCollection flds = new SqlDbTableFieldCollection();

            while (r.Read())
                flds.Add(SqlDbTableField.Build(conn, r));


            return flds;
        }
    }
}
